package com.cristina.attention.pending;

import cn.hutool.core.collection.CollUtil;
import com.cristina.attention.domain.MessageInfo;
import com.cristina.attention.handler.HandlerHolder;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;

/**
 * Task 执行器 (非 IM 业务)
 *
 * @author by superman
 */
@Data
@Accessors(chain = true)
@Slf4j
public class Task implements Runnable {

    @Resource
    private HandlerHolder handlerHolder;

    /**
     * 非 im 业务需要单条处理
     */
    private MessageInfo messageInfo;

    @Override
    public void run() {
        if (!CollUtil.isNotEmpty(messageInfo.getReceiver())) {
            return;
        }
        handlerHolder.route(messageInfo.getSendChannel()).doHandler(messageInfo);
    }
}
